
if exists (select 1 from sysobjects where name = 'vw_initgrid' and type = 'V')
begin
   drop view vw_initgrid
   print 'View: vw_initgrid deleted ...'
end
go
create view vw_initgrid
as
     select top 1000
          d.PlanID, 
          d.PrsID, 
          p.Nachname, 
          p.Vorname, 
          a.Prozent 
       from Dienstplan d 
 inner join Person p 
         on p.PrsId = d.PrsID 
and p.PersonTyp = 1
 inner join Arbeitspensum a 
         on a.PrsID = p.PrsId 
--        and a.status = 1 
--and a.von <= @datum 
and a.Bis = (select max(Bis) from Arbeitspensum ab where ab.PrsID = p.PrsId)
   group by d.PrsID, d.PlanID, p.Nachname, p.Vorname, a.Prozent
   order by d.PlanID
go
print 'View: vw_initgrid done ...'
go

grant select on vw_initgrid to prsadmins with grant option
go
grant select on vw_initgrid to prsusers
go


